import { getHomePageData, getGoodsList } from '@/services/home.js';

// eslint-disable-next-line import/no-anonymous-default-export
export default {
  namespace: 'home',
  state: {
    items: [
    ],
    page: {},
    list: []
  },
  reducers: {
    setState(state, { payload }) {
      // console.log(payload);
      return {
        ...state,
        ...payload
      }
    },
    setGoodsList(state, { payload }) {
      // console.log(payload);
      return {
        ...state,
        list: payload
      }
    }
  },
  effects: {
    *getPageDataDetail({ payload }, { call, put }) {
      const detail = yield call(getHomePageData);
      console.log(detail);
      yield put({
        type: 'setState',
        payload: detail.data.pageData
      });
    },
    *getPageDataGoodsList({ payload }, { call, put }) {
      const list = yield call(getGoodsList);
      yield put({
        type: 'setGoodsList',
        payload: list
      })
    }
  },
}